package com.trivia.restServices

import com.trivia.AppUser;
import com.trivia.Level;
import com.trivia.Score;
import com.trivia.restResponses.SaveScoreResponse;
import com.trivia.restResponses.ServerResponse;

class SaveScoreController extends AbstractController {
	
	def scoreService

    def index = {
		execute()
	}
	
	def executeTry(){
		Level level = Level.get(Long.parseLong(params.levelID))
		AppUser appUser = AppUser.get(Long.parseLong(params.userID))
		int correctAnswers = Integer.parseInt(params.correctAnswers)
		int incorrectAnswers = Integer.parseInt(params.incorrectAnswers)
		int notAnswers = Integer.parseInt(params.notAnswers)
		long time = Long.parseLong(params.time)
		
		def score = scoreService.saveScore(level, appUser, correctAnswers, incorrectAnswers, notAnswers, time)
		
		response = new SaveScoreResponse(status: ServerResponse.okResponse,description: ServerResponse.responses[ServerResponse.okResponse],score:score)
	}
}
